<template>
	<view class="goods-list-box">
		<my-goods v-for="(item,i) in goods_list" :key="i" :goods="item" @click="gotoDetail(item)"></my-goods>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {query: '',cid: '',pagenum: 1,pagesize: 10},
				goods_list:[],
				total:0,
				isloading:false
			}
		},
		onLoad(options){
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.getGoodsList()
		},
		methods:{
			async getGoodsList(){
				this.isloading = true
				const {data:res} = await uni.$http.get("/api/public/v1/goods/search",this.queryObj)
				if (res.meta.status!==200){
					uni.$showMsg()
				}else{
					this.goods_list.push(...res.message.goods)
					this.total = res.message.total
					this.isloading=false
				}
			},
			gotoDetail(item){
				uni.navigateTo({
					url:'/subpkg/goods_detail/goods_detail?goods_id='+item.id
				})
			}
		},
		onReachBottom(){
			if (this.queryObj.pagenum*this.queryObj.pagesize>=this.total){
				uni.$showMsg('数据已加载完毕')
				return
			}
			if (this.isloading==false){
				this.queryObj.pagenum+=1
				this.getGoodsList()
			}
		}
	}
</script>

<style lang="scss">

</style>
